///\todo upgrade

//////////////////////////////////////////////////////////////////////////////////
//                                                                              //
//  This file is part of the buola project (https://code.google.com/p/buola/).  //
//                                                                              //
//  Copyright(c) 2007-2012 Xavi Gratal                                          //
//  gratal AT gmail DOT com                                                     //
//                                                                              //
//  Buola is free software: you can redistribute it and/or modify               //
//  it under the terms of the GNU General Public License as published by        //
//  the Free Software Foundation, either version 3 of the License, or           //
//  (at your option) any later version.                                         //
//                                                                              //
//  Buola is distributed in the hope that it will be useful,                    //
//  but WITHOUT ANY WARRANTY; without even the implied warranty of              //
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               //
//  GNU General Public License for more details.                                //
//                                                                              //
//  You should have received a copy of the GNU General Public License           //
//  along with buola.  If not, see <http://www.gnu.org/licenses/>.              //
//                                                                              //
//////////////////////////////////////////////////////////////////////////////////

#ifndef _BUOLA_DBUS_AUTO_TRAITS_H_
#define _BUOLA_DBUS_AUTO_TRAITS_H_

#include <buola/buola.h>
#include <array>
#include <map>

#define DECLARE_DBUS_TRAITS(type,sig)                                                            \
    template<>                                                                                   \
    struct MSignature<type>                                                                      \
    {                                                                                            \
        static const char *Get()   {   return sig;    }                                          \
    }

namespace buola { namespace dbus {

//get the dbus signature of a type
    
template<typename tType>
struct MSignature;

template<typename tType>
struct MSignature<std::vector<tType>>
{
    static const char *Get()
    {
        static const std::string lName=std::string("a")+MSignature<tType>::Get();
        return lName.c_str();
    }
};

template<typename t1,typename t2>
struct MSignature<std::map<t1,t2>>
{
    static const char *Get()
    {
        static const std::string lName=std::string("a{")+MSignature<t1>::Get()+MSignature<t2>::Get()+"}";
        return lName.c_str();
    }
};

DECLARE_DBUS_TRAITS(char,"y");
DECLARE_DBUS_TRAITS(int8_t,"y");
DECLARE_DBUS_TRAITS(uint8_t,"y");
DECLARE_DBUS_TRAITS(int16_t,"n");
DECLARE_DBUS_TRAITS(uint16_t,"q");
DECLARE_DBUS_TRAITS(int32_t,"i");
DECLARE_DBUS_TRAITS(uint32_t,"u");
DECLARE_DBUS_TRAITS(int64_t,"x");
DECLARE_DBUS_TRAITS(uint64_t,"t");
DECLARE_DBUS_TRAITS(float,"d");
DECLARE_DBUS_TRAITS(double,"d");
DECLARE_DBUS_TRAITS(const char*,"s");
DECLARE_DBUS_TRAITS(std::wstring,"s");
DECLARE_DBUS_TRAITS(std::string,"s");
DECLARE_DBUS_TRAITS(io::CURI,"s");
DECLARE_DBUS_TRAITS(UValue,"(ss)");
DECLARE_DBUS_TRAITS(CPath,nullptr);
DECLARE_DBUS_TRAITS(CObjectPath,"o");
DECLARE_DBUS_TRAITS(CMember,nullptr);
DECLARE_DBUS_TRAITS(CInterface,nullptr);

/*namespace dbus*/ } /*namespace buola*/ }

#endif
